<template>
    <div class="contion">
        <div class="search">
            <div class="search-1">
                <van-icon name="arrow-left" size="25" style="color:black;margin-top:5px" @click="home"/>
            </div>            
            <div class="search-2">
                <van-icon name="search" size="30" style="margin-left:10px;margin-top:4px"/>
                <span style="margin-top:12px;margin-left:10px">搜索</span>
                <el-input v-model="query.value" placeholder="请输入内容" style="width:300px;margin-left:16px"></el-input>
                <el-button type="primary" style="width:70px;height:49px;margin-left:20px" @click="search">搜索</el-button>
            </div>
            <div class="search_2">
                <span style="font-size:18px"><b>最近搜索</b></span>
                <span style="color:#E44F32;font-size:18px;margin-left:260px" @click="shoe">清空</span>
                <div  v-for="(j,k) in querylist" :key="k"  class="search_2_1">
                    <span style="width:180px;height:40px;background-color:#9F9E9A1D;color:darkgray;font-size:18px;margin-left:20px;"> 
                        <van-icon name="replay" size="20" style="margin:10px"/>
                        {{ j.name }}
                    </span>
                </div>
            </div>
            <div class="search-3">
                    <span style="font-size:18px"><b>热门产品</b></span>
                    <span style="color:#E44F32;font-size:18px;margin-left:200px" @click="shoe">查看全部</span>
                <div class="search-3_1" v-for="(j,k) in querylist" :key="k" >
                    <img :src="j.image" style="width:120px;height:120px;margin-bottom:20px">
                    <div class="search-3_2">
                        <span style="font-size:18px;">{{ j.name }}</span>
                        <span>{{ j.price }}</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import {ref,onMounted} from "vue"
import {ElMessage} from 'element-plus'
import axios from 'axios'
import {useRouter} from 'vue-router'

const router = useRouter()

const home = () => {
    router.push('/home')
}

let querylist = ref([])

const getquery = () => {
    axios.get("http://127.0.0.1:8000/home/a2/").then(res => {
        // console.log(res)
        querylist.value = res.data.data
    })
}


let query = ref({
    name: '',
    price: '',
    cate: '',
    ca:'',
    page:1,
    size:3
})

let data = ref([])
const search = () => {
    axios.get("http://127.0.0.1:8000/home/shoe/",query.value).then(res => {
            data.value = res.data
            // console.log(data.value)
            ElMessage.success('搜索成功')
        })
}

onMounted(() => {
    getquery()
})
</script>

<style scoped>
.contion{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    vertical-align: middle;
}

.search{
    width: 700px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /*background-color: aqua;*/
}

.search-1{
    width: 500px;
    height: 40px;
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: 1000;
    background-color: #FFFFFF;
    border: #FFFFFF solid 0px;
}

.search-2{
    width: 500px;
    height: 50px;
    display: flex;
    flex-direction: row;
    background-color: #9F9E9A1D;
    border-radius: 10px;
    margin-top: 30px;
}

.search_2{
    margin-top: 40px;
}

.search_2_1{
    margin-top: 20px;
    display: flex;
    flex-direction: row;
}

.search-3{
    margin-top: 150px;
}

.search-3_1{
    display: flex;
    flex-direction: row;
    margin-top: 20px;
}

.search-3_2{
    display: flex;
    flex-direction: column;
    margin-left: 20px;
    margin-top: 30px;
}
</style>